package core

import (
	"g_ansible/router"
	"github.com/gin-gonic/gin"
)

// InitRouter 初始化路由
func InitRouter() *gin.Engine {
	// 设置gin模式
	//gin.SetMode(global.Config.System.Env)
	Router := gin.Default()
	//Router.Use(middleware.GinLogger(), middleware.GinRecover(true))

	// 使用gin会话路由
	//var store = cookie.NewStore([]byte(global.Config.System.SessionsSecret))
	//Router.Use(sessions.Sessions("session", store))
	// 将指定目录下的文件提供给客户端
	// "uploads" 是URL路径前缀，http.Dir("uploads")是实际文件系统中存储文件的目录
	//Router.StaticFS(global.Config.Upload.Path, http.Dir(global.Config.Upload.Path))
	// 创建路由组
	routerGroup := router.RouterGroupApp

	//publicGroup := Router.Group(global.Config.System.RouterPrefix)
	//privateGroup := Router.Group(global.Config.System.RouterPrefix)
	//adminGroup := Router.Group(global.Config.System.RouterPrefix)
	//privateGroup.Use(middleware.JWTAuth())
	//adminGroup.Use(middleware.JWTAuth(), middleware.AdminAuth())
	//{
	v1 := Router.Group("v1")
	routerGroup.InitBaseRouter(v1)
	routerGroup.InitHostRouter(v1)
	routerGroup.InitPlayRouter(v1)
	routerGroup.InitGroupRouter(v1)
	v2 := Router.Group("v2")
	routerGroup.InitV2PlayRouter(v2)
	routerGroup.InitV2HostRouter(v2)
	//}
	//{
	//	routerGroup.InitUserRouter(privateGroup, publicGroup, adminGroup)
	//}

	return Router
}
func RunServer() {
	addr := "8088"
	Router := InitRouter()

	Router.Run(":" + addr)
}
